package com.booking.springrestful.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booking.springrestful.domain.Homepagetexts;
import com.booking.springrestful.mapper.HomepagetextsMapper;
import com.booking.springrestful.service.HomepagetextsService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author 13182
* @description 针对表【homepagetexts】的数据库操作Service实现
* @createDate 2025-03-05 16:37:01
*/
@Service
public class HomepagetextsServiceImpl extends ServiceImpl<HomepagetextsMapper, Homepagetexts>
    implements HomepagetextsService {

    @Resource
    private HomepagetextsMapper homepagetextsMapper;

    @Override
    public void saveText(Homepagetexts homepagetexts) {
        homepagetexts.setLastModified(new Date());
        homepagetextsMapper.insert(homepagetexts);
    }

    @Override
    public void updateText(Homepagetexts homepagetexts) {
        Homepagetexts one = homepagetextsMapper.selectOne(new QueryWrapper<Homepagetexts>().eq("sectionName", homepagetexts.getSectionName()));
        BeanUtils.copyProperties(homepagetexts,one);
        one.setLastModified(new Date());
        homepagetextsMapper.updateById(one);
    }

    @Override
    public List<Homepagetexts> getText() {
        return homepagetextsMapper.selectList(null);
    }
}




